package com.ctshk.app.cms.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.cms.dto.*;
import com.ctshk.rpc.cms.req.AppHomeCMSReq;
import com.ctshk.rpc.cms.req.AppHomeHotRecommendSearchReq;
import com.ctshk.rpc.cms.service.IAppHomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * App首页控制器
 * </p>
 *
 * @author lys
 * @since 2021/06/15
 */
@Api(value = "首页管理-PC", tags = "首页管理-PC")
@RestController
@RequestMapping("/pc/home")
public class PCHomeController extends BaseController {

    @DubboReference
    private IAppHomeService iAppHomeService;

    @ApiOperation(value = "PC首页-CMS聚合", notes = "PC首页-CMS聚合")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/cms")
    public Result<PcHomeCmsDTO> getCMSInfo(@RequestBody AppHomeCMSReq req) {
        TokenUser currentUser = null;
        try {
            currentUser = getCurrentUser();
        } catch (Exception e) {
        }
        return iAppHomeService.getPCHomeCMS(req,currentUser);
    }

    @ApiOperation(value = "PC首页-分组信息", notes = "PC首页-分组信息")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/group/{channelId}")
    public Result<PCHomeProductGroupDTO> groupInfo(@PathVariable("channelId") Long channelId) {
        TokenUser currentUser = null;
        try {
            currentUser = getCurrentUser();
        } catch (Exception e) {
        }
        return iAppHomeService.pcGroupInfo(channelId, currentUser);
    }

    @ApiOperation(value = "PC首页-分组产品搜索", notes = "PC首页-分组产品搜索")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/search/group")
    public Result<List<HomeHotRecommendDTO>> groupSearch(@RequestBody @Valid AppHomeHotRecommendSearchReq req) {
        TokenUser currentUser = null;
        try {
            currentUser = getCurrentUser();
        } catch (Exception e) {
        }
        return iAppHomeService.groupSearch(req,currentUser);
    }

}